<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!--允许全屏-->
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta content="telephone=no,email=no" name="format-detection">
    <meta name="referrer" content="no-referrer">
    <meta name="applicable-device" content="mobile">
    <meta http-equiv="Content-Type" content="text/html">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover">
    <meta name="format-detection" content="email=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-title" content="My App">
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="full-screen" content="yes">
    <meta name="browsermode" content="application">
    <meta name="x5-page-mode" content="app">
    <meta name="x5-fullscreen" content="true">
    <meta name="x5-orientation" content="portrait">
    <meta name="screen-orientation" content="portrait">
    <meta name="baidu-site-verification" content="OlHm31P42t" />
    <link rel="stylesheet" href="/static/css/app/workspace/otherSettings/otherSettings.css">
    <script src="/static/js/app/workspace/jquery.min.js"></script>
    <script src="/static/js/app/workspace/flexible.js"></script>
    <script src="/static/js/app/workspace/init.js"></script>
    <script src="/static/js/app/workspace/util.js"></script>
    <title>其他设置</title>
    <style>
        html,body{-webkit-text-size-adjust: 100%;-webkit-tap-highlight-color: rgba(0, 0, 0, 0);}
    </style>
</head>
<body>
<script src="/static/js/common/Monitor.js"></script>
    <div class="settings">
        <!--<div class="loading">-->
            <!--<div>-->
                <!--<img src="../img/loading.gif" alt="">-->
                <!--<p>加载中...</p>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="seting-top">-->
            <!--<h1>其他设置</h1>-->
            <!--<img src="../img/return.png" alt="">-->
        <!--</div>-->
        <div class="seting-box">
            <div class="seting-radio">
                <p><b>视频接听</b><i id="radio" class=""></i><span class="price" id="price"></span></p>
                <p><b>私信收费</b><i id="charge" class=""></i><span class="fee" id="fee"></span></p>
                <p id="changeNote"><b>小纸条</b><span class="count" id="count"></span></p>
            </div>
            <div class="seting-price">
                <p><b id="totalBal"></b><span>花瓣</span></p>
                <i>收益的花瓣</i>
                <button id="putForward">提现</button>
            </div>
        </div>
        <div class="message hide" id="message"></div>
        <div class="popup hide">
            <div class="attestation hide">
                <h1>设置价格</h1>
                <div class="seting-price">
                    <input id="setingPrice" type="text">
                    <b>花瓣 / 价格</b>
                </div>
                <p>100花瓣=1元，建议输入50-75花瓣/分钟</p>
                <p>(请输入50-500花瓣/分钟)</p>
                <div class="popup-btn">
                    <span class="cancel">取消</span>
                    <span class="sure" id="sure">确定</span>
                </div>
            </div>
            <div class="reminder hide">
                <h1>温馨提示</h1>
                <p>自拍认证审核通过后，才可设置50-500花瓣/分钟</p>
                <div class="popup-btn">
                    <span class="cancel">取消</span>
                    <span class="sure" id="sure2">立即认证</span>
                </div>
            </div>
            <div class="reminder auditing hide">
                <h1>温馨提示</h1>
                <p>自拍认证正在审核中...</p>
                <p></p>
                <div class="popup-btn">
                    <span class="sure" id="sure3">确定</span>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(function () {
            // $(".loading").addClass("hide");
            var accessId = getParameter("x-access-id");
            var accessToken = getParameter("x-access-token");
            var ua = "h5";
            var H=window.innerHeight;
            $(".settings").css("height",H);
            var flag1="",flag2="";
            //初始化页面
            loader();
            //初始化
            function loader(){
                $.ajax({
                    url: genUrl("/customer/findCustomerInfo"),
                    type: 'GET',
                    contentType:"application/json",
                    headers:{
                        "x-access-id":accessId ,
                        "x-access-token": accessToken,
                        "x-ua": ua
                    },
                    data: {"customerId":accessId},
                    dataType: 'json',
                    async: false,
                    success: function (res) {
                        if(res.code!=0){
                            alert(res.message);
                            return;
                        }
                        var customerInfo=res.data.customerInfo;
                        var certification=customerInfo.certification;//0->审核中  1->审核通过  2->审核失败
                        var videoOnOff=customerInfo.videoOnOff;     // 0->视频关 1->开
                        var messageOnOff=customerInfo.messageOnOff;// 0->私信关 1->开
                        var videoCollectFees=parseInt(customerInfo.videoCollectFees);//私信50花瓣每分钟
                        var totalBal=res.data.account.gainsBal;//花瓣收益
                        $("#price").html(videoCollectFees+"花瓣/分钟");
                        $("#totalBal").html(totalBal);
                        $("#count").html(res.data.account.notes)
                        //初始化视频和私信是否开启或关闭
                        isSwitch(videoOnOff,"#radio");
                        isSwitch(messageOnOff,"#charge","#fee","免费","收费");
                        //设置价格
                        $("#price").click(function () {
                            if(certification==1){//审核通过
                                $(".popup,.attestation").removeClass("hide");
                                $(".reminder,.auditing").addClass("hide");
                            }else if(certification==2 || certification==""){
                                $(".popup,.reminder").removeClass("hide");
                                $(".attestation,.auditing").addClass("hide");
                            }else if(certification==0){
                                $(".popup,.auditing").removeClass("hide");
                                $(".attestation").addClass("hide");
                            }
                        });
                       flag1 = videoOnOff == 0 ? true : false;
                       flag2 = messageOnOff == 0 ? true : false;
                    }
                });
            }
            //取消关闭弹窗
            $(".cancel,#sure3").click(function () {
                $(".popup,.attestation,.reminder").addClass("hide");
                $("#setingPrice").val("");
            });
            //设置价格确定（弹窗）
            $("#sure").click(function () {
                var setingPrice=$("#setingPrice").val();
                if(setingPrice==" " || setingPrice<50 || setingPrice>500){
                    $("#message").html("请输入50-500花瓣/每分钟");
                    $("#message").removeClass("hide");
                    hideMsg();
                }else{
                    $.ajax({
                        url: genUrl("/app/updateVideoFees"),
                        type: 'GET',
                        contentType:"application/json",
                        headers:{
                            "x-access-id":accessId ,
                            "x-access-token": accessToken,
                            "x-ua": ua
                        },
                        data: {"price":parseInt(setingPrice)},
                        dataType: 'json',
                        async: false,
                        success: function (res) {
                            if(res.code!=0){
                                alert(res.message);
                                return;
                            }
                            loader();
                            $(".popup,.attestation,.reminder").addClass("hide");
                            $("#setingPrice").val("");
                        }
                    });

                }
            });
            //立即认证
            $("#sure2").click(function () {
                window.location.href="http://test.huakai.me/go2authentication.html"
            });
            // $("#sure3").click(function () {
            //     window.location.href="https://www.huakai.me/entrance.html";
            // });
            $("#changeNote").click(function () {
               window.location.href="changeNotes.html?x-access-id="+accessId+"&x-access-token="+accessToken;
            })
            // 提现
            $("#putForward").click(function () {
                //获取当前地址前部分
                var href = window.location.href;
                var pos = href.indexOf("/app/");
                var base_url = href.slice(0, pos);
                window.location.href=base_url+"/app/pay/putForward/zfbforward.html?x-access-id="+accessId+"&x-access-token="+accessToken+"";
            })
            //视频和私信切换
            switchs("#radio",flag1,"video","视频接听已开启","视频接听已关闭");
            //相互关注私信收费开启   相互关注私信收费关闭
            switchs("#charge",flag2,"message","相互关注私信收费开启","相互关注私信收费关闭","收费","免费");
            // 间隔2s消失
            function hideMsg(){
                setTimeout(function () {
                    $("#message").addClass("hide");
                },2000);
            }
            //判断视频和私信是否开启或关闭
            function isSwitch(isOff,ele1,ele2,msg1,msg2) {
                if(isOff==0){
                    flag=0;
                    $(ele1).addClass("close");
                   $(ele2).html(msg1);
                }else{
                    flag=1;
                    $(ele1).removeClass("close");
                    $(ele2).html(msg2);
                }
            }
            //开关接口
            function switchAjax(onoff,type) {
                $.ajax({
                    url: genUrl("/customer/v2/customerSetting"),
                    type: 'GET',
                    contentType:"application/json",
                    headers:{
                        "x-access-id":accessId ,
                        "x-access-token": accessToken,
                        "x-ua": ua
                    },
                    data: {
                        "customerId":accessId,
                        "onoff" : onoff,
                        "type" : type
                    },
                    dataType: 'json',
                    async: false,
                    success: function (res) {
                        if(res.code!=0){
                            alert(res.message);
                            return;
                        }
                    }
                });
            }
            ////视频和私信切换
            function switchs(ele,flag,type,msg1,msg2,msg3,msg4) {
                $(ele).click(function () {
                    if(flag){
                        flag=false;
                        $("#message").html(msg1);
                        $("#message").removeClass("hide");
                        hideMsg();
                        $("#fee").html(msg3);
                        var onoff=Number(!flag);
                        switchAjax(onoff,type);
                    }else{
                        flag=true;
                        $("#message").html(msg2);
                        $("#message").removeClass("hide");
                        hideMsg();
                        $("#fee").html(msg4);
                        var onoff=Number(!flag);
                        switchAjax(onoff,type);
                    }
                    $(ele).toggleClass("close");
                })
            }

        });
    </script>
</body>
</html>